package socket;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Clientt {
    private Socket socket;
    public Clientt(){
        System.out.println("正在连接服务端");
        try {
            socket = new Socket("176.15.14.32",8808);
            System.out.println("成功连接服务端");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {

            OutputStream out = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_8);
            PrintWriter pw = new PrintWriter(osw,true);
            Scanner scanner = new Scanner(System.in);
            String str;
            while(true){
                str = scanner.nextLine();
                if("exit".equals(str)){
                    pw.println("再见");
                    pw.close();
                }
            pw.println(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[]args){
        Clientt clientt = new Clientt();
        clientt.start();
    }
}
